package com.sky.controller.admin;


import com.sky.dto.EmployeeLoginDTO;
import com.sky.result.Result;
import com.sky.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author majun
 * @package com.sky.controller.admin
 * @date 2025/6/21 01:27
 */

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * 登录
     * @param employeeLoginDTO 员工登录信息
     * @return token 登录结果
     */
    @PostMapping("/login")
    private Result login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {

        log.info("员工登录：{}", employeeLoginDTO);

        if (employeeLoginDTO.getUsername() == null || employeeLoginDTO.getPassword() == null) {
            return Result.error("用户名或密码不能为空");
        }

        String token = adminService.login(employeeLoginDTO);

        return Result.success(token);

    }

}
